package com.supor.aiot.food.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.android.baseconfig.common.views.CircleImageView;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.supor.aiot.food.R;
import com.supor.aiot.food.bean.RecipeHotBean;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

public class MutiAvatarAdapter extends RecyclerView.Adapter<MutiAvatarAdapter.MutiAvatarHolder>{
    private List<RecipeHotBean.MutiAvatarBean> mList;
    private Context mContext;
    private RecipeDeviceAdapter.onRecipeDeviceClick recipeDeviceClick;
    public MutiAvatarAdapter(List<RecipeHotBean.MutiAvatarBean> mList, Context mContext) {
        this.mList = mList;
        this.mContext = mContext;
    }

    @NonNull
    @Override
    public MutiAvatarAdapter.MutiAvatarHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(mContext).inflate(R.layout.item_muti_avatar,parent, false);
        return new MutiAvatarAdapter.MutiAvatarHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MutiAvatarAdapter.MutiAvatarHolder holder, int position) {
        if (position==mList.size()-1){
            setMargins(holder.ivProductor,0,0,0,0);
        }
    }

    public void setMargins (View v, int l, int t, int r, int b) {
        if (v.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
            ViewGroup.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) v.getLayoutParams();
            p.setMargins(l, t, r, b);
            v.requestLayout();
        }
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    public class MutiAvatarHolder extends RecyclerView.ViewHolder{
        public CircleImageView ivProductor;
        public RelativeLayout rlVavatarOuter;
        public MutiAvatarHolder(@NonNull View itemView) {
            super(itemView);
            ivProductor=itemView.findViewById(R.id.iv_mutiavatar);
            rlVavatarOuter=itemView.findViewById(R.id.rl_mutiavatar_outer);
        }
    }

}
